package design_pattern;

/**
 * @ClassName Multiton
 * @Deacription TODO
 * @Author 谢忠辉
 * @Date 2021/3/17 0017 20:37
 **/
public class Season {
    private String name ;
    private static final Season spring =  new Season("春季");
    private static Season summer = new Season("夏季");
    private static Season autumn = new Season("秋季");
    private static Season winter = new Season("冬季");

    private static Season[] seasons = new Season[]{new Season("春季"),  new Season("夏季"),new Season("秋季"), new Season("冬季")};
    private static String[] enSeasonsName = new String[]{"春季","夏季","秋季","冬季"};
    private static String[] chSeasonsName = new String[]{"spring","summer","autumn","winter"};
    private Season(){
    }
    private Season( String name){
        this.name = name ;
    }

    public static Season getInstance( String name ){
        switch (name){
            case "春季":return spring ;
            case "夏季":return summer ;
            case "秋季":return autumn ;
            case "冬季":return winter ;
            default: throw new RuntimeException("参数错误");
        }
    }
    public static Season getInstance2( String name ){
        for (int i = 0; i < seasons.length; i++) {
            if (name.equalsIgnoreCase(enSeasonsName[i])||name.equalsIgnoreCase(chSeasonsName[i]) ){
                return seasons[i] ;
            }
        }
        return null;
    }

}
